package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/15.<br><br>
 *
 * 判断子序列
 */
public class Topic392 {
    public static void main(String[] args) {
        Topic392 instance = new Topic392();

        System.out.println(instance.isSubsequence("abc", "ahbgdc"));
        System.out.println(instance.isSubsequence("axc", "ahbgdc"));
        System.out.println(instance.isSubsequence("", "ahbgdc"));
        System.out.println(instance.isSubsequence("a", "abc"));
    }

    public boolean isSubsequence(String s, String t) {
        if(s.length() == 0) {
            return true;
        }

        int startS = 0;
        int startT = 0;

        char[] arrayS = s.toCharArray();
        char[] arrayT = t.toCharArray();
        while (startS < arrayS.length && startT < arrayT.length) {
            if(arrayS[startS] == arrayT[startT]) {
                startS++;
            }

            startT++;
        }

        return startS == arrayS.length;
    }
}
